<template>
  <div class="app-container">
    <div class="layout-content">
      <van-cell center title="待办事项">
        <template #right-icon>
          <van-switch
            @input="onInput('dealWith')"
            v-model="model.dealWith"
            size="24"
          />
        </template>
      </van-cell>
      <van-cell center title="接受任务">
        <template #right-icon>
          <van-switch
            @input="onInput('Receive')"
            v-model="model.Receive"
            size="24"
          />
        </template>
      </van-cell>
    </div>
    <div class="layout-footer">
      <TabBar :activeTab="4"></TabBar>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { ACCESS_TOKEN, TENANT_ID } from "@/store/mutation-types";
import TabBar from "@/components/TabBar";
import Cookies from "js-cookie";
import { postAction } from "@/api/manage";
import { mapActions } from "vuex";
export default {
  data() {
    return {
      userInfo: {},
      model: {
        dealWith: true,
        Receive: true,
      },
      url: {
        edit: "sys/user/edit",
      },
    };
  },
  created() {
    this.userInfo = this.$store.getters.userInfo;
    console.log(this.userInfo);
    this.model.dealWith = this.userInfo.isShowTodo === "0";
    this.model.Receive = this.userInfo.isShowReceive === "0";
  },
  methods: {
    ...mapActions(["SetToken"]),
    onInput(type) {
      console.log(this.model.dealWith);
      console.log(this.model.Receive);
      this.userInfo.isShowTodo = this.model.dealWith ? 0 : 1;
      this.userInfo.isShowReceive = this.model.Receive ? 0 : 1;
      postAction(this.url.edit, this.userInfo).then((res) => {
        if (res.success) {
          console.log(res);
          console.log(Vue.ls.get(ACCESS_TOKEN));
          console.log(this.userInfo);
          this.SetToken({
            token: Vue.ls.get(ACCESS_TOKEN),
            userInfo: this.userInfo,
          });
        }
      });
      console.log(type);
    },
  },
  components: {
    TabBar,
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  .layout-content {
    .van-cell {
      margin: 20px 0;
    }
  }
}
</style>
